
package com.craterhill.java.ems.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import com.craterhill.java.ems.common.beans.Country;
import com.craterhill.java.ems.common.beans.State;
import com.craterhill.java.ems.dao.impl.AbstractDao;
import com.craterhill.java.ems.dao.utils.EMSResultSetExtractor;

public interface StateDao extends EMSDao<State> {

	public final String FIELD_LIST = "obj.state_id, obj.country_id, obj.state_code, obj.state_name" + AbstractDao.MONITER_FIELDS;

	public final String FIND_ALL_STATE = "select " + FIELD_LIST + " from state obj";

	public final String FIND_STATE_BY_COUNTRY = FIND_ALL_STATE + " where country_id = ?";

	public List<State> findByCountry(final int countryId);

	public final class StateExtractor extends EMSResultSetExtractor<State> {

		@Override
		protected State extractResultSetData(ResultSet resultSet) throws SQLException {
			State state = new State();
			state.setStateId(resultSet.getInt(1));

			Country country = new Country();
			country.setCountryId(resultSet.getInt(2));

			state.setStateCode(resultSet.getString(3));
			state.setStateName(resultSet.getString(4));
			state.setStatus(resultSet.getBoolean(5));
			state.setCreatedBy(resultSet.getInt(6));
			state.setCreatedDate(resultSet.getDate(7));
			state.setModifiedDate(resultSet.getDate(8));
			return state;
		}
	}
}
